//package com.erik.lin.controller;
//
//import com.erik.lin.activemq.consumer.QueueConsumerService;
//import com.erik.lin.activemq.producer.ProducerService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Controller;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestMethod;
//import org.springframework.web.bind.annotation.ResponseBody;
//
//import javax.annotation.Resource;
//import javax.jms.Destination;
//import javax.jms.TextMessage;
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * Created by Erik on 2017/4/26.
// */
//@Controller
//@RequestMapping("/activemq")
//public class ActiveMqDemoController {
//
//    //队列名defaultActiveMqQueueDestination
//    @Resource(name = "defaultActiveMqQueueDestination")
//    private Destination defaultActiveMqQueueDestination;
//
//    //主题名defaultActiveMqTopicDestination
//    @Resource(name = "defaultActiveMqTopicDestination")
//    private Destination defaultActiveMqTopicDestination;
//
//    //消息生产者
//    @Autowired
//    private ProducerService producerService;
//
//    //队列消息消费者
//    @Autowired
//    private QueueConsumerService queueConsumerService;
//
//    @RequestMapping(value = "/testSend", method = RequestMethod.GET)
//    public @ResponseBody Map<String, Object> testSend() {
//        Map rs = new HashMap<String, Object>();
//        String message = "justTestSend";
//        try {
//            producerService.sendMessageToTopic(defaultActiveMqQueueDestination, message);
//            rs.put("success", true);
//        }catch (Exception e){
//            rs.put("success", false);
//            rs.put("msg", e.getMessage());
//            e.printStackTrace();
//        }finally {
//            return rs;
//        }
//
//    }
//
//    @RequestMapping(value = "/testRecFromQueue", method = RequestMethod.GET)
//    public @ResponseBody Map<String, Object> testRec1() {
//        Map rs = new HashMap<String, Object>();
//        try {
//            TextMessage tm = queueConsumerService.receive(defaultActiveMqQueueDestination);
//            rs.put("success", true);
//            rs.put("message", tm.getText());
//        }catch (Exception e){
//            rs.put("success", false);
//            rs.put("msg", e.getMessage());
//            e.printStackTrace();
//        }finally {
//            return rs;
//        }
//    }
//
//}
